package com.smy.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smy.reggie.common.BaseContext;
import com.smy.reggie.common.R;
import com.smy.reggie.pojo.Orders;
import com.smy.reggie.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
        log.info("前端数据"+ orders);
        orderService.submit(orders);
        return R.success("下单完成！");
    }
    @GetMapping("/userPage")
    public R<Page<Orders>> page(Integer page,Integer pageSize){
        Page<Orders> pageInfo = new Page<>(page,pageSize);
        Long currentId = BaseContext.getCurrentId();
        LambdaQueryWrapper<Orders> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Orders::getUserId,currentId);
        return R.success(orderService.page(pageInfo, wrapper));
    }
}
